Skip to content

Conversation

@Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Jan 12, 2026

BINARY_OP_SUBSCR_INIT_FRAME is the opcode for subscripting custom __getitem__.

LOAD_ATTR_PROPERTY is the opcode for loading an attribute decorated with @property.

I see a solid 0.5-1% speedup from this PR alone on Sam's fastmark (pyperformance subset).

@Fidget-Spinner Fidget-Spinner changed the title gh-131798: JIT: Support custom binary op and property frames gh-131798: JIT optimizer: Support custom binary op and property frames Jan 12, 2026
@savannahostrowski savannahostrowski self-requested a review January 13, 2026 04:25
uops = get_opnames(ex)

self.assertIn("_BINARY_OP_SUBSCR_INIT_CALL", uops)
# _POP_TOP_NOP is a sign the optimizer ran and didn't hit bottom.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# _POP_TOP_NOP is a sign the optimizer ran and didn't hit bottom.
# _POP_TOP_NOP is a sign the optimizer ran and didn't bail out.

Not sure if it's just me but maybe this is a clearer phrasing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bottom is the actual term for contradiction used in the JIT optimizer. It's an obscure academic term, so let me change it to contradiction.

new_frame = PyJitRef_NULL;
ctx->done = true;
assert((this_instr + 2)->opcode == _PUSH_FRAME);
PyCodeObject *co = get_code_with_logging(this_instr + 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to add a comment about why are using +2, since I don't know if it's abundantly clear? IIUC, it's because _SAVE_RETURN_OFFSET is between _LOAD_ATTR_PROPERTY_FRAME and _PUSH_FRAME.

Comment on lines 3569 to 3570
import dis
dis.dis(testfunc, adaptive=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import dis
dis.dis(testfunc, adaptive=True)

Leftover from debugging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops yes, thanks!

break;
}
_Py_UOpsAbstractFrame *f = frame_new(ctx, co, 0, NULL, 0);
f->locals[0] = owner;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to check if frame is NULL before this, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an excellent catch, thank you. We could've let in a segfault because of this!

@bedevere-app
Copy link

bedevere-app bot commented Jan 13, 2026

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants